<template>
    <div class="blog-header">
        <h1 class="blog-title">{{ blog.title }}</h1>
        <div class="blog-meta">
            <router-link :to="`/userSpace/${blog.authorId}`" class="author-link">
                <span>{{ blog.userName }}</span>
            </router-link>
            <span class="date">{{ formatDate(blog.createdAt) }}</span>
        </div>
        <div class="blog-tags">
            <router-link v-for="tag in blog.tags" :key="tag" :to="{
                name: 'Home',
                query: {
                    searchType: BlogSearchType.GetSearch,
                    searchKeyWord: tag
                }
            }" class="tag-link">
                <el-tag class="tag" size="small" effect="light">
                    {{ tag }}
                </el-tag>
            </router-link>
        </div>
    </div>
</template>

<script setup lang="ts">
import { BlogRead } from '@/types/blogType';
import { BlogSearchType } from '@/types/serchType';

const props = defineProps<{
    blog: BlogRead
}>();

const formatDate = (dateString: string) => {
    const date = new Date(dateString);
    return date.toLocaleDateString('zh-CN', {
        year: 'numeric',
        month: 'long',
        day: 'numeric'
    });
};
</script>

<style scoped>
.blog-header {
    width: 600px;
    /* max-width: 800px; */
    margin: 20px auto;
    padding: 0 20px;
}

.blog-title {
    font-size: 2.5em;
    margin-bottom: 16px;
    color: #2c3e50;
}

.blog-meta {
    display: flex;
    gap: 16px;
    color: #666;
    font-size: 0.9em;
}

.author-link {
    color: #3498db;
    text-decoration: none;
    font-weight: 500;
}

.author-link:hover {
    text-decoration: underline;
}

.date {
    color: #666;
}

.blog-tags {
    margin-top: 12px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.tag-link {
    text-decoration: none;
}

.tag {
    font-size: 12px;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.tag:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
</style>